/* eslint-disable padded-blocks */
/* eslint-disable spaced-comment */
/* eslint-disable no-multiple-empty-lines */
/* eslint-disable no-unused-vars */
import axios from 'axios'
import { Message } from 'element-ui'
import Cookies from 'js-cookie'
const service = axios.create({
  baseURL: process.env.VUE_APP_UPLOAD,
  timeout: 3600 * 1000 // request timeout
})


service.interceptors.request.use(config => {
  if (Cookies.get('X-Token') && Cookies.get('X-Token') !== undefined) {
    config.headers['X-Token'] = Cookies.get('X-Token')
  }

  return config
}, error => {
  console.log(error) // for debug
  Promise.reject(error)
})
service.interceptors.response.use(
  response => {
    if (response.data && response.data.code === 200) {
      return response.data
    }
    if (response.data && response.data.code === 511) {
      return response.data
    } else {
      if (response.data.code === 401 || response.data.code === 101) {
        // store.commit('app/set_login_dialog_isShow', true)
      }
      return Promise.reject(response.data)
    }
  },
  error => {
    console.log('err' + error) // for debug
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })
    return Promise.reject(error)
  })

export default service
